package com.tank.model;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.tank.config.ResourceMgr;

/**
 * TODO
 *
 * @author chenwb
 * @since 2024/1/27 22:28
 */
public class Explode {
    private int x, y;
    private BufferedImage[] bufferedImages;

    private boolean isAlive = true;
    private int step = 0;
    ExecutorService executorService = Executors.newFixedThreadPool(10);

    public Explode(int x, int y) {
        this.x = x;
        this.y = y;
        this.bufferedImages = ResourceMgr.getExplodeImages();
        // executorService.execute(AudioFactory.getInstance().getExplodeAudio()::play);
    }

    public void paint(Graphics g) {
        if (step >= bufferedImages.length) {
            this.isAlive = false;
            return;
        }
        g.drawImage(bufferedImages[step++], x, y - this.bufferedImages[0].getHeight() / 4, null);
    }

    public boolean isAlive() {
        return !this.isAlive;
    }
}
